import axios from 'axios';
import NProgress from 'nprogress'; // 进度条
import 'nprogress/nprogress.css'; // 进度条样式
// import swal from 'sweetalert'
import Vue from "vue";


const instance = axios.create({
    baseURL:'http://localhost:8080',
    timeout:4000
})

instance.interceptors.request.use(config=>{
    NProgress.start()
    return config;
},error => {
    return Promise.reject(error)
})

instance.interceptors.response.use(resp=>{
    NProgress.done()
    return resp;
},error => {
    NProgress.done()
    const errResp = error.response
    errorHandler(errResp)
    return Promise.reject(error)
})

const errorHandler = ({data,message,status})=>{
    if (status===500){
        var vo = new Vue();
        vo.$breadstick.notify(`❌服务器故障！！`)
        // swal(`❌ ${message}---服务器故障！！`,{button:false})
    }
}

export default instance;

